<template>
   <div class="wrapper loginsign"> 
  
   <div class="item"> 
    <div class="form"> 
     <h3 class="loginsign-title">用户登录</h3> 
     <form class="sui-form login-form"> 
      <div class="control-group"> 
       <label for="inputname" class="control-label">手机号：</label> 
       <div class="controls"> 
        <input type="text" v-model="pojo.username" placeholder="11位手机号" class="input-xlarge" data-rules="required"> 
       </div> 
      </div> 
      <div class="control-group"> 
       <label for="inputpassword" class="control-label">密码：</label> 
       <div class="controls"> 
        <input type="text" v-model="pojo.password" placeholder="输入登录密码" class="input-xlarge"> 
       </div> 
      </div> 
      <div class="controls"> 
       <label> <input type="checkbox" name="remember-me"><span class="type-text" style="font-size:12px;">记住登录状态</span> </label> 
       <button type="button" class="sui-btn btn-danger btn-yes" @click="doLogin">登 录</button> 
      </div> 
      <div class="other-methods"> 
      </div> 
     </form> 
     <div id="weixin"></div>
     <img src="">
    </div> 
   </div> 
  </div>
</template>
<script>
import '~/assets/css/page-sj-person-loginsign.css'
import userApi from '@/api/user'
import {setUser} from '@/utils/auth'
export default {
    data(){
      return {
        pojo:{}
      }
    },
    methods:{
      doLogin(){
        userApi.login(this.pojo).then(res =>{
          //登录成功后
            if(res.data.flag){
               //将用户的信息存入Cookie中
                setUser(res.data.data.token,res.data.data.name,res.data.data.avatar)
                location.href='/friends'
            }else{
                this.$message({
                    message: res.data.message,
                    type: 'error'
                })
                this.pojo= {}
            }
        })
      }
    },
    mounted(){
      var obj = new WxLogin({
        id: "weixin",
        appid: "wx3bdb1192c22883f3",
        scope: "snsapi_login",
        redirect_uri: "http://note.java.itcast.cn/weixinlogin"
      });    
    },
    head:{
      script:[
        {src:'http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js'}
      ]
    }
}
</script>
